package controller.v2;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import model.DicVO;
import model.LogOrder;
import model.LogOrderBack;
import model.MemberVO;
import model.OrderBackVO;
import model.OrderGoodVO;
import model.OrderVO;
import model.SeqVO;
import service.v2.AddressService;
import service.v2.ApplyReturnService;
import service.v2.MemberService;
import service.v2.OrderService;
import util.DeliverUtil;
import util.OssUtil;
import util.PackageUtil;
import util.PropertieUtil;

@Controller
@RequestMapping("/v2/applyret")
public class ApplyReturnController {

	@Autowired
	private ApplyReturnService applyReturnService;
		
	/**
	 * 查询所有快递公司
	 * @param token
	 * @param member_id
	 * @param memberVO
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/checkDeliver",method=RequestMethod.GET) 
	public Object checkDeliver(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)String member_id,
			MemberVO memberVO) throws Exception{
		List<DicVO>  dicList = applyReturnService.getDicByParentId(PropertieUtil.loadPropertie("express_delivery"));
		return PackageUtil.packageParams(200,"successs",dicList,"");
	}
		
	@ResponseBody
	@RequestMapping(value="/checkDeliverEn",method=RequestMethod.GET) 
	public Object checkDeliverEn(@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)String member_id,
			MemberVO memberVO) throws Exception{
		List<DicVO>  dicList = applyReturnService.getDicByParentId(PropertieUtil.loadPropertie("inter_ems_name"));
		return PackageUtil.packageParams(200,"successs",dicList,"");
	}
	
	/**
	 * 存退货图片
	 * @param img
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/saveOrderBackFile",method=RequestMethod.POST) 
	public Object saveOrderBackFile(@RequestParam(value="img",required = false)MultipartFile img) throws Exception{
		SimpleDateFormat df = new SimpleDateFormat("yyMM");
		String file_name ="";
		String path = "uploadfile/service/"+ df.format(new Date())+"/";
		if(img!=null){
			file_name = OssUtil.uploadFile(img, path);
		}
		System.out.println(file_name);
		return PackageUtil.packageParams(200,"successs",file_name,"");
	}
		
	/**
	 * 删除图片
	 * @param file_path
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/delOrderBackFile",method=RequestMethod.POST) 
	public Object delOrderBackFile(String file_path) throws Exception{
		OssUtil.deleteFile(file_path);
		return PackageUtil.packageParams(200,"successs","","");
	}
}
